<?php
  
$application = __DIR__;
$modules = __DIR__.'/../kohana/modules';
$system = __DIR__.'/../kohana/system';

define('DOCROOT', realpath(__DIR__).DIRECTORY_SEPARATOR);
define('APPPATH', realpath($application).DIRECTORY_SEPARATOR); 
define('MODPATH', realpath($modules).DIRECTORY_SEPARATOR);
define('SYSPATH', realpath($system).DIRECTORY_SEPARATOR);
unset($application, $modules, $system);

require SYSPATH.'classes/Kohana.php';

date_default_timezone_set('Asia/Shanghai');
setlocale(LC_ALL,"chs");

spl_autoload_register(array('Kohana', 'auto_load'));
ini_set('unserialize_callback_func', 'spl_autoload_call');


Kohana::$environment = Kohana::DEVELOPMENT;
//Kohana::$environment = Kohana::PRODUCTION;

if (Kohana::$environment == Kohana::PRODUCTION) {
    error_reporting(E_ALL ^ E_NOTICE ^ E_STRICT);
} else {
    error_reporting(E_ALL | E_STRICT);
    ini_set('display_errors', TRUE);
}

Kohana::init(array(
	'base_url' => '/',
	'index_file' => false,
));

Kohana::modules(array(
	'database'   => MODPATH.'database',
	'helper'     => MODPATH.'helper',
));
Kohana::$log->attach(new Log_File(APPPATH.'logs'));

Route::set('default', '(<controller>(/<action>))')->defaults(array('controller' => 'home'));
Route::set('catch_all', '<path>', array('path' => '.+'))->defaults(array('controller' => 'Error','action' => '404'));

if (Kohana::$environment == Kohana::PRODUCTION) {
    try {
        echo Request::instance()->execute();
    } catch(Exception $e) {
        //Kohana_Exception::log($e);
        $errmsg = Kohana_Exception::text($e);
    	Kohana::$log->add(Klog::ERROR, $errmsg);
    }
} else {
    echo Request::instance()->execute();
}
